/*二次封装uni.request*/
/*import.meta.env.VITE_APP_BASE_API*/
const baseUrl = 'http://web.pfcc.io/h5'


let countClient = 0; //计数器，为多次调用接口准备
const request = (options = {}) =>{
    countClient++;
    // uni.showLoading({
    //     title: 'loading...',
    //     mask: true
    // }).then(()=>{})

    return new Promise((resolve,reject)=>{
        uni.request({
            url:baseUrl + options.url || '',   //baseUrl
            method: options.method || 'POST',  //请求方法（默认post）
            data: options.data || {},          //携带数据
            responseType: options.responseType || '',
            dataType: options.dataType || '',
            header: {
                'Device-Code':'92jks2h34g2j4j3',
                'Content-Type':'application/json; charset=utf-8',
                'Accept-Language': uni.getStorageSync('Accept-Language'),
            },  //请求头携带token
            success(res) {
                resolve(res)
            },
            fail(err) {
                reject(err)
            },
            complete() {
                countClient--;
                if(countClient === 0){
                    // wx.hideLoading()
                }
            }
        })
    })
}


export default request